export default function cutHighlight(myChart, option, time = 2) {
  let currentIndex = -1;
  let dataLen = option.series[0].data.length;
  let Time = null;

  function cut() {
    clearInterval(Time);

    Time = setInterval(() => {
      // console.log("00000", myChart.id);
      //取消之前高亮的图形
      myChart.dispatchAction({
        type: "downplay",
        seriesIndex: 0,
        dataIndex: currentIndex,
      });
      currentIndex = (currentIndex + 1) % dataLen;
      //高亮当前图形
      myChart.dispatchAction({
        type: "highlight",
        seriesIndex: 0,
        dataIndex: currentIndex,
      });
      //显示tooltip
      myChart.dispatchAction({
        type: "showTip",
        seriesIndex: 0,
        dataIndex: currentIndex,
      });
    }, time * 1000);
  }
  cut();

  const Fn_cease = (params) => {
    // 用户鼠标悬浮到某一图形时，停止自动切换并高亮鼠标悬浮的图形
    clearInterval(Time);
    if (currentIndex != params.dataIndex) {
      myChart.dispatchAction({
        type: "downplay",
        seriesIndex: 0,
        dataIndex: currentIndex,
      });
      currentIndex = params.dataIndex;
    }
    console.log("销毁");
  };
  myChart.on("mouseover", Fn_cease);

  myChart.on("mouseout", (params) => {
    // 用户鼠标移出时，重新开始自动切换
    clearInterval(Time);
    cut();
  });
  return Time;
}
